<template>
<div>
<!--  {{parmas}}-->
  <table >
    <tr v-for="i in parmas" :key="i">
      <td>{{i.lable}}:</td>0

      <td v-if="i.type=='select'"  >
        <select v-model="values[i.lable]">
          <option v-for="j in i.values" :key="j" :value="j.name">{{j.name}}</option>
        </select>
      </td>

      <td v-else-if="i.type=='textarea'">
        <textarea cols="30" rows="10"></textarea>
      </td>
      <td v-else-if="i.type=='file'">
        <input type="file" id="pic" @change="img(i.lable)">
      </td>
      <td v-else>
        <input :type="i.type" v-model="values[i.lable]">
      </td>

    </tr>
  </table>
  <button style="height:40px;width:90px;background-color: #ffd500"  @click="submit">提交</button>
  {{values}}

</div>
</template>

<script>
import axios from 'axios'
export default {
  name: "show_setparmas",
  data(){
    return{
      parmas:[],
      id:this.$route.query.id,
      values:{},
      img1:''
    }
  },
  methods:{
    get_parmas(){
      axios({url:'work/getparmas?id='+this.id,method:'get'}).then(res=>{
        console.log(res.data.list)
        this.parmas = JSON.parse(res.data.list.parmas)
      })
    },
    submit(){
      console.log(this.values)
      let userid=localStorage.getItem('userid')
      let formdata = new FormData()
      formdata.append('pic',JSON.stringify(this.values))
      formdata.append('userid',userid)

      axios({url:'work/holiday',method:'post',data:formdata}).then(res=>{
        if(res.data.code==200){
          this.$toast.success('提交成功')
        }
      })
    },
    img(lable){
      let formdata = document.getElementById('pic').files[0]
      this.values[lable] = formdata['name']
      console.log(formdata)

    }
  },
  mounted() {
    this.get_parmas()
  }

}
</script>

<style scoped>

</style>